<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>用值将数组填补到指定长度</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-multisort.html">array_multisort</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-pop.html">array_pop</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-pad" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_pad</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">array_pad</span> &mdash; <span class="dc-title">
     用值将数组填补到指定长度
    </span></p>

   </div>
   
 <div class="refsect1 description" id="refsect1-function.array-pad-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_pad</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$input</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$pad_size</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$pad_value</code></span>
   )</div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_pad()</strong></span> 返回
     <em><code class="parameter">input</code></em> 的一个拷贝，并用
     <em><code class="parameter">pad_value</code></em> 将其填补到
     <em><code class="parameter">pad_size</code></em> 指定的长度。如果
     <em><code class="parameter">pad_size</code></em> 为正，则数组被填补到右侧，如果为负则从左侧开始填补。如果
     <em><code class="parameter">pad_size</code></em> 的绝对值小于或等于
     <em><code class="parameter">input</code></em> 数组的长度则没有任何填补。有可能一次最多填补
     1048576 个单元。
    </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.array-pad-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">input</code></em></dt>

     <dd>

      <p class="para">
       Initial array of values to pad.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">pad_size</code></em></dt>

     <dd>

      <p class="para">
       New size of the array.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">pad_value</code></em></dt>

     <dd>

      <p class="para">
       Value to pad if <em><code class="parameter">input</code></em> is less than
       <em><code class="parameter">pad_size</code></em>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-pad-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a copy of the <em><code class="parameter">input</code></em> padded to size specified
   by <em><code class="parameter">pad_size</code></em> with value 
   <em><code class="parameter">pad_value</code></em>. If <em><code class="parameter">pad_size</code></em> is 
   positive then the array is padded on the right, if it&#039;s negative then 
   on the left. If the absolute value of <em><code class="parameter">pad_size</code></em> is less
   than or equal to the length of the <em><code class="parameter">input</code></em> then no
   padding takes place.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-pad-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4872">
    <p><strong>Example #1 <span class="function"><strong>array_pad()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$input&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">12</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">9</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;result&nbsp;is&nbsp;array(12,&nbsp;10,&nbsp;9,&nbsp;0,&nbsp;0)<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;result&nbsp;is&nbsp;array(-1,&nbsp;-1,&nbsp;-1,&nbsp;-1,&nbsp;12,&nbsp;10,&nbsp;9)<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"noop"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;not&nbsp;padded<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.array-pad-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.array-fill.html" class="function" rel="rdfs-seeAlso">array_fill()</a> - 用给定的值填充数组</span></li>
    <li class="member"><span class="function"><a href="function.range.html" class="function" rel="rdfs-seeAlso">range()</a> - 建立一个包含指定范围单元的数组</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-multisort.html">array_multisort</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-pop.html">array_pop</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
